﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PortalWeb.Core.Entity;

namespace PortalWeb.Dao.Mapping
{
    public class SystemFunctionMap : EntityTypeConfiguration<Function>
    {
        public SystemFunctionMap()
        {
            // Table & Column Mappings
            this.ToTable("Functions");

            this.HasMany(t => t.Roles)
                .WithMany(t => t.Functions)
                .Map(m =>
                {
                    m.ToTable("RoleFunction");
                    m.MapLeftKey("FunctionId");
                    m.MapRightKey("RoleId");
                });

            // Relationships
            this.HasOptional(t => t.Parent)
                .WithMany(t => t.Children)
                .HasForeignKey(d => d.ParentId);

            this.HasRequired(t => t.OperatorUser)
                .WithMany()
                .HasForeignKey(d => d.Operator);
        }
    }
}
